<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>04-文字</title>
  <style>
    body {
      background-color: #000;
      text-align: center;
    }
    #c1 {
      background-color: #fff;
    }
  </style>
</head>
<body>
  <canvas id="c1" width="1000" height="800"></canvas>

  <script>
    window.onload = function() {
      const oC = document.getElementById('c1')
      const gd = oC.getContext('2d')

      // 1. 创建img元素
      const img = new Image()
      // 2. 图片加载完成后显示
      img.onload = function () {
        gd.drawImage(img, 0, 0, 1920/2, 990/2)
      }
      // 3. 设置图片源地址
      img.src = 'bg.jpg'
    }
  </script>
</body>
</html>